package logic

import (
	"context"
	"develop/model/mysql"
	"develop/usersrpc/internal/svc"
	"develop/usersrpc/usersrpc"
	"errors"
	"github.com/zeromicro/go-zero/core/logx"
)

type CommentDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCommentDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentDelLogic {
	return &CommentDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CommentDelLogic) CommentDel(in *usersrpc.CommentDelRequest) (*usersrpc.CommentDelResponse, error) {
	// todo: add your logic here and delete this line
	var findUserId mysql.User_info
	err := findUserId.FindId(mysql.DB, in.UserId)
	if err != nil {
		return nil, err
	}
	if findUserId.ID == 0 {
		return nil, errors.New("用户不存在")
	}
	commentInfo := mysql.Comment_Info{
		User_id: int(in.UserId),
	}
	err = commentInfo.CommentDel(mysql.DB, in.UserId)
	if err != nil {
		return nil, err
	}
	return &usersrpc.CommentDelResponse{}, nil
}
